//
//  TiXianController.m
//  DianDangDai
//
//  Created by bhf on 2017/12/19.
//  Copyright © 2017年 bhf. All rights reserved.
//

#import "TiXianController.h"
#import "AttributedIntString.h"
#import "HomePageViewController.h"
@interface TiXianController ()
@property (nonatomic, assign) BOOL changeBtn;
@property (nonatomic, copy) NSString *fangshi;
@end

@implementation TiXianController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    self.navigationController.navigationBar.translucent = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"提现";
    _fangshi = @"1";
    // Do any additional setup after loading the view.
}

- (void)setupViews {
    self.bottomBtn.layer.cornerRadius = 22;
    NSString *newStr = [NSString stringWithFormat:@"账户余额%@元",self.zonge];
    AttributedIntString *abi = [[AttributedIntString alloc] init];
    self.topLabel.attributedText = [abi attributedStringWithString:newStr setTextColor:[UIColor colorWithHex:@"#333333"]];
    
    [_money addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    self.usableBalance.text = _keyong;
}
- (IBAction)changeBtn:(UIButton *)sender {
    if (sender.tag == 101) {
        [sender setImage:[UIImage imageNamed:@"radio1-1"] forState:UIControlStateNormal];
        [_btn2 setImage:[UIImage imageNamed:@"radio2-1"] forState:UIControlStateNormal];
        float shouxufei = ([_money.text floatValue]*0.5/1000)+2;
        _poundage.text = [NSString stringWithFormat:@"%.2f",shouxufei];
    } else if (sender.tag == 102) {
        [sender setImage:[UIImage imageNamed:@"radio1-1"] forState:UIControlStateNormal];
        [_btn1 setImage:[UIImage imageNamed:@"radio2-1"] forState:UIControlStateNormal];
        float shouxufei = 2;
        _poundage.text = [NSString stringWithFormat:@"%.2f",shouxufei];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)tixian:(UIButton *)sender {
    NSString * string = [self.usableBalance.text substringWithRange:NSMakeRange(0, [self.usableBalance.text length] - 1)];
    self.money.text = string;
    
}

#pragma mark - TextField

-(void)textFieldDidChange :(UITextField *)theTextField{

    if (theTextField.text.length<1) {
        [UIView animateWithDuration:0.2 animations:^{
            _top.constant = 20;
        }];
        _shouxufei.hidden = YES;
    } else {
        [UIView animateWithDuration:0.2 animations:^{
            _top.constant = 80;
        }];
        _shouxufei.hidden = NO;
        float shouxufei = ([theTextField.text floatValue]*0.5/1000)+2;
        _poundage.text = [NSString stringWithFormat:@"%.2f",shouxufei];
    }
}

- (IBAction)tixianfangshi:(UIButton *)sender {
    
    if (sender.tag == 101) {
        _fangshi = @"1";
    } else if (sender.tag == 102) {
        _fangshi = @"3";
    }
    
}
- (IBAction)queren:(UIButton *)sender {
    UIStoryboard *board = [UIStoryboard storyboardWithName:@"HomePage" bundle:[NSBundle mainBundle]];
    HomePageDetailController *hpdc = [board instantiateViewControllerWithIdentifier:@"hpdc"];
    hpdc.hidesBottomBarWhenPushed = YES;
    hpdc.titleStr = @"提现";
    NSString *urlString = [NSString stringWithFormat:@"%@OPT=1048&sign=%@&amount=%@&type=%@",API_LOGIN_URL_STRING,USER_SIGN,self.money.text,_fangshi];
    hpdc.filepath = [NSURL URLWithString:urlString];
    [self showViewController:hpdc sender:self];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
